<script>
	export default {
		onLaunch: function() {
			let that = this
			let userInfo = uni.getStorageSync('userInfo')
			let venueId = uni.getStorageSync('venueId')
			let venueName = uni.getStorageSync('venueName')
			if (userInfo) {
				that.$store.commit('saveUserInfo', userInfo);
			}
			if (venueId) {
				that.$store.commit('setVenueId', venueId);
				that.$store.commit('setVenueName', venueName);
			}

			// #ifdef MP-WEIXIN
			let appId = uni.getAccountInfoSync().miniProgram.appId
			// #endif 
			// #ifdef MP-TOUTIAO
			let appId = uni.getEnvInfoSync().microapp.appId
			// #endif 
			// #ifdef H5
			let appId = that.$store.state.gzhId
			// #endif 
			let shopId = 1
			let logo =
				'XXXXXXXXX'
			that.$app.ajax({
				data: {
					param: {
						appId
					}
				},
				api: that.$api.getPzobj()
			}).then((resd) => {
				if (resd.record.shopId) {
					shopId = resd.record.shopId
				}
				if (resd.record.logo) {
					logo = resd.record.logo
				}
				that.$store.commit('setShopid', shopId);
				uni.setStorage({
					key: 'logo',
					data: logo
				});
				uni.setStorage({
					key: 'appName',
					data: resd.record.appName || 'DM跳跳'
				});
				// #ifdef MP
				uni.login({
					// #ifdef MP-WEIXIN
					provider: 'weixin',
					// #endif 
					// #ifdef MP-TOUTIAO
					provider: 'toutiao',
					// #endif 
					success: (loginRes) => {
						that.$app.ajax({
							data: {
								param: {
									code: loginRes.code
								}
							},
							api: that.$api.getUser()
						}).then((res) => {
							that.$store.commit('setOpenId', res.record.openId)
							if (res.record.nickName) {
								that.$store.commit('saveUserInfo', res.record);
							}
							that.$app.ajax({
								data: {
									param: {
										openId: res.record.openId
									}
								},
								api: that.$api.getSessionId()
							}).then((resb) => {})
							that.$app.ajax({
								data: {
									param: {}
								},
								api: that.$api
									.getRenovationInfo()
							}).then((resc) => {
								if (resc.errorCode ===
									'000000' && resc.record
								) {
									let val = resc
										.record || {}
									that.$store.commit(
										'setColor', val
										.color1);

									that.$store.commit(
										'setShopHome', val
										.shopHome);
									that.$store.commit(
										'setImgHost',
										val.path);
									that.$store.commit(
										'setRenovationInfo',
										val)
									let theme =
										'--color:' + val
										.color1 +
										'; --phb:linear-gradient(270deg, ' +
										val.color1 +
										' 0%, ' + val
										.color2 +
										' 100%);' +
										'--more-color:' +
										val.color3 +
										';--bjColor:#f7f7f7'+
										';--color2:' + val
										.color2 +
										';--blue-bg:linear-gradient(270deg, ' +
										val.color3 +
										' 0%, ' + val
										.color4 + ' 100%);'
									that.$store.commit(
										'setTheme',
										theme);
									let tabUrl = val
										.navigationList
										.map(e => e.url)
									that.$store.commit(
										'setTabUrl',
										tabUrl);
									setTimeout(() => {
										that.$isResolve()
									}, 300)
								}
							})
							that.$app.ajax({
								data: {
									param: {
										codes: 'RESOURCE_PATH'
									}
								},
								api: that.$api.getUrl()
							}).then((resc) => {
								that.$store.commit(
									'setOssHost', resc
									.recordList[0]
									.val)
							})
						}).catch(() => {})
					}
				})
				// #endif 
				// #ifdef H5
				that.$app.ajax({
					data: {
						param: {}
					},
					api: that.$api
						.getRenovationInfo()
				}).then((resc) => {
					if (resc.errorCode ===
						'000000' && resc.record
					) {
						let val = resc
							.record || {}
						that.$store.commit(
							'setColor', val
							.color1);
						that.$store.commit(
							'setImgHost',
							val.path);
						that.$store.commit(
							'setRenovationInfo',
							val)
						let theme =
							'--color:' + val
							.color1 +
							'; --phb:linear-gradient(270deg, ' +
							val.color1 +
							' 0%, ' + val
							.color2 +
							' 100%);' +
							';--bjColor:#f7f7f7'+
							'--more-color:' +
							val.color3 +
							';--color2:' + val
							.color2 +
							';--blue-bg:linear-gradient(270deg, ' +
							val.color3 +
							' 0%, ' + val
							.color4 + ' 100%);'
						that.$store.commit(
							'setTheme',
							theme);
						let tabUrl = val
							.navigationList
							.map(e => e.url)
						that.$store.commit(
							'setTabUrl',
							tabUrl);
					}
				})
				that.$app.ajax({
					data: {
						param: {
							codes: 'RESOURCE_PATH'
						}
					},
					api: that.$api.getUrl()
				}).then((resc) => {
					that.$store.commit(
						'setOssHost', resc
						.recordList[0]
						.val)
				})
				if (uni.getStorageSync('token')) {
					that.$app.ajax({
						data: {
							param: {}
						},
						api: that.$api.memberInformation()
					}).then((res) => {
						if (res.errorCode === '000000') {
							that.$store.commit('saveUserInfo', res.record);
							that.$store.commit('setVenue', true);
						}
					}).catch(() => {})
					that.$isResolve()
				} else {
					that.$isResolve()
					that.$app.jump('/pages/home/loginb');
				}

				// #endif  

			}).catch(() => {})

		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	@import './common/index.scss';
</style>